package com.jappyframework;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;

import com.sun.mirror.declaration.ClassDeclaration;

public class Logger {
	
	public static void log(String msg) {
		if (mPW == null) {
			init();
		}
		mPW.write(msg);
		mPW.flush();
	}
	
	public static void log(ClassDeclaration cd) {
		log("simple=" + cd.getSimpleName() + "qualified=" + cd.getQualifiedName());
	}
	
	public static void log(Exception e) {
		log(e.getMessage());
		e.printStackTrace(mPW);
		mPW.flush();
	}
	
	private static PrintWriter mPW;
	private static File mFile;

	private static void init() {
		try {
			mFile = new File("/mnt/data/logs/apt.log");
			mPW = new PrintWriter(mFile);
		} catch (Exception e) {
			mPW = new PrintWriter(System.err);
			e.printStackTrace();
		}
	}
	
	@Override
	protected void finalize() throws Throwable {
		mPW.flush();
		mPW.close();
	}
}
